window.addEventListener("hashchange", sz_DynamicHtmlHashChange);

/**
 *
 */
function sz_DynamicHtmlHashChange() {
    if (sz_ConstantsService.isLogin() != true) {
        sz_Html5LogService.execute(location.hash);
    }
}

window.addEventListener('popstate', function (event) {
    sz_DynamicHtmlUrlChange(event.state);
});

function sz_DynamicHtmlUrlChange(url) {
    if (sz_ConstantsService.isLogin() != true) {
        sz_Html5LogService.execute(url);
    }
}

var sz_currentUri = "";

function sz_urlChange() {
    try {
        if (sz_currentUri != window.location.href) {
            sz_currentUri = window.location.href;
            sz_DynamicHtmlUrlChange(window.location.href);
            // console.log("changed => " + currentUri);
        }
    } catch (e) {

    }

}

$(function () {
    setInterval('sz_urlChange()', 1000);
})


var sz_uid = sz_StringHelper.randomString(22);

var sz_Html5LogService = {
    execute: function (hash) {
        var productId = sz_RequestHelper.getParameter("productId");
        if (sz_StringHelper.isEmpty(productId)) {
            productId = sz_RequestHelper.getQueryStringFromUrl(sz_RequestHelper.getLoadJsUrl(), "productId");
        }

        var params = {
            url: window.location.href,
            pageName: document.title,
            hash: hash,
            productId: productId,
            uid: sz_uid,
            connectionType: sz_BrowserHelper.connectionType(),
            openTime: new Date().getTime()
        };

        var userBean = sz_ConstantsService.getItem($sz_Constants.USER_BEAN);
        $.ajax({
            type: "POST",
            url: $sz_Config.productShowLogURL.format({token: userBean.token}),
            contentType: "application/json", //必须有
            dataType: "json", //表示返回值类型，不必须
            data: JSON.stringify(params),  //相当于 //data: "{'str1':'foovalue', 'str2':'barvalue'}",
            success: function (config) {
                //alert(JSON.stringify(config));
                //weChatShareConfig(config, weChatConfig);
            },
            error: function () {
                //CambioLog.error("shareConfigURL error");
            }
        });
    }
}